<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/template.xhtml">
	<ui:define name="title">
		SGMF :: Motorista
	</ui:define>
	
	<ui:define name="content">
		<h:form id="form">
			<h:inputHidden id="motorista_id" value="#{motoristaBean.motorista.id}" rendered="#{motoristaBean.motorista.id != null}" />
			<h:inputHidden id="endereco_id" value="#{motoristaBean.endereco.id}" rendered="#{motoristaBean.endereco.id != null}" />
			<p:fieldset legend="Motorista">
				<p:panelGrid columns="3" styleClass="borderless">
					<p:outputLabel value="Matrícula" for="matricula" />
					<p:inputText id="matricula" type="text" label="Matrícula" value="#{motoristaBean.motorista.matricula}" required="true" maxlength="6" size="50" />
					<p:message for="matricula" />
					<p:outputLabel value="Nome" for="nome" />
					<p:inputText id="nome" type="text" label="Nome" value="#{motoristaBean.motorista.nome}" required="true" maxlength="50" size="50" />
					<p:message for="nome" />
					<p:outputLabel value="CPF" for="cpf" />
					<p:inputMask id="cpf" label="CPF" value="#{motoristaBean.motorista.cpf}" required="true" mask="999.999.999-99" size="50">
                        <f:validator binding="#{cpfValidator}" />
                    </p:inputMask>
					<p:message for="cpf" />
					<p:outputLabel value="CNH" for="cnh" />
					<p:inputText id="cnh" label="CNH" value="#{motoristaBean.motorista.cnh}" required="true"  maxlength="11" size="50">
						<f:convertNumber type="number" />
					</p:inputText>
					<p:message for="cnh" />
                    <p:outputLabel value="Função" for="funcao" />
                    <p:selectOneMenu id="funcao" value="#{motoristaBean.motorista.funcao}" converter="#{funcaoConverter}" required="true">
                        <f:selectItem itemValue="#{null}" itemLabel="-- Selecione --" />
                        <f:selectItems value="#{motoristaBean.funcoes}" var="funcao" itemValue="#{funcao}" itemLabel="#{funcao.nome}" />
                    </p:selectOneMenu>
                    <p:message for="funcao" />
                    <p:outputLabel value="Setor" for="setor" />
                    <p:selectOneMenu id="setor" value="#{motoristaBean.motorista.setor}" required="true" converter="#{setorConverter}">
                        <f:selectItem itemValue="#{null}" itemLabel="-- Selecione --" />
                        <f:selectItems value="#{motoristaBean.setores}" var="setor" itemValue="#{setor}" itemLabel="#{setor.nome}" />
                    </p:selectOneMenu>
                    <p:message for="setor" />
				</p:panelGrid>
			</p:fieldset>
			<br />
			<p:fieldset legend="Endereço">
				<p:panelGrid columns="3" styleClass="borderless">
					<p:outputLabel value="CEP" for="cep" />
					<p:inputMask id="cep" label="CEP" value="#{motoristaBean.endereco.cep}" required="true" mask="99.999-999" size="50" />
					<p:message for="cep" />
					<p:outputLabel value="Estado" for="estado" />
					<p:selectOneMenu id="estado" value="#{motoristaBean.endereco.estado}" required="true">
						<f:selectItem itemValue="#{null}" itemLabel="-- Selecione --" />
						<f:selectItems value="#{motoristaBean.estados}" var="estado" itemValue="#{setor}" itemLabel="#{estado}" />
					</p:selectOneMenu>
					<p:message for="estado" />
					<p:outputLabel value="Cidade" for="cidade" />
					<p:inputText id="cidade" type="text" label="Cidade" value="#{motoristaBean.endereco.cidade}" required="true" maxlength="50" size="50" />
					<p:message for="cidade" />
					<p:outputLabel value="Bairro" for="bairro" />
					<p:inputText id="bairro" type="text" label="Bairro" value="#{motoristaBean.endereco.bairro}" required="true" maxlength="50" size="50" />
					<p:message for="bairro" />
					<p:outputLabel value="Logradouro" for="logradouro" />
					<p:inputText id="logradouro" type="text" label="Logradouro" value="#{motoristaBean.endereco.logradouro}" required="true" maxlength="50" size="50" />
					<p:message for="logradouro" />
					<p:outputLabel value="Número" for="numero" />
					<p:inputText id="numero" type="text" label="Número" value="#{motoristaBean.endereco.numero}" required="true" maxlength="6" size="50">
						<f:convertNumber type="number" />
					</p:inputText>
					<p:message for="numero" />
					<p:outputLabel value="Complemento" for="complemento" />
					<p:inputText id="complemento" type="text" label="Complemento" value="#{motoristaBean.endereco.complemento}" required="true" maxlength="50" size="50" />
					<p:message for="complemento" />
				</p:panelGrid>
			</p:fieldset>
			<br />
			<p:commandButton value="Novo" update="display" icon="ui-icon-new" />
			<p:commandButton id="salvar" value="Salvar"	action="#{motoristaBean.salvar}" update=":growl, :form, :datatable_form" icon="ui-icon-disk" />
		</h:form>
		<br />
		<h:form id="datatable_form">
			<p:dataTable id="datatable" var="motorista"
				value="#{motoristaBean.motoristas}" rows="10" paginator="true"
				paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
				currentPageReportTemplate="({currentPage} de {totalPages})" rowsPerPageTemplate="10,20,30" emptyMessage="Nenhum registro encontrado.">
				<f:facet name="header">
		        	Lista de Motoristas
		    	</f:facet>
				<p:column headerText="Matrícula">
					<h:outputText value="#{motorista.matricula}" />
				</p:column>
				<p:column headerText="Nome">
					<h:outputText value="#{motorista.nome}" />
				</p:column>
				<p:column headerText="CPF">
					<h:outputText value="#{motorista.cpf}" />
				</p:column>
				<p:column headerText="CNH">
					<h:outputText value="#{motorista.cnh}" />
				</p:column>
                <p:column headerText="Função">
                    <h:outputText value="#{motorista.funcao.nome}" />
                </p:column>
                <p:column headerText="Setor">
                    <h:outputText value="#{motorista.setor.nome}" />
                </p:column>
				<p:column headerText="Ações" styleClass="column-action">
					<p:commandButton icon="ui-icon-pencil" title="Editar" actionListener="#{motoristaBean.editar(motorista)}" update=":growl, :form" />
					<p:commandButton icon="ui-icon-trash" title="Excluir" actionListener="#{motoristaBean.excluir(motorista)}" update=":growl, datatable">
						<p:confirm header="Confirmação" message="Deseja realmente excluir este motorista" icon="ui-icon-alert" />
					</p:commandButton>
				</p:column>
			</p:dataTable>
		</h:form>
	</ui:define>
</ui:composition>

</html>